package com.itheima.tlias84.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tlias84.annotaion.Log;
import com.itheima.tlias84.dto.SelectClazzDTO;
import com.itheima.tlias84.dto.SelectEmpDTO;
import com.itheima.tlias84.entity.Clazz;
import com.itheima.tlias84.mapper.ClazzMapper;
import com.itheima.tlias84.mapper.EmpMapper;
import com.itheima.tlias84.po.*;
import com.itheima.tlias84.service.ClazzService;
import com.itheima.tlias84.utils.ResultUtil;
import com.itheima.tlias84.vo.PageVO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
@Service
public class ClazzServiceImpl implements ClazzService {
    @Resource
    ClazzMapper clazzMapper;
    @Resource
    EmpMapper empMapper;
    @Override
    public ResultUtil selectClazzByPage(SelectClazzPageParam param) {
        Page<Object> page = PageHelper.startPage(param.getPage(), param.getPageSize());
        List<SelectClazzDTO> dtos = clazzMapper.selectClazzByPage(param);
        PageVO <SelectClazzDTO> pageVO = new PageVO<>();
        pageVO.setRows(dtos);
        pageVO.setTotal(page.getTotal());
        return ResultUtil.success(pageVO);
    }

    @Log
    @Override
    public int deleteById(Integer id) {
        return clazzMapper.deleteById(id);
    }

    @Log
    @Override
    public int insertClazz(InsterClazzParam param) {
        param.setCreateTime(LocalDateTime.now());
        param.setUpdateTime(LocalDateTime.now());
        int i = clazzMapper.insertClazz(param);
        return i;
    }

    @Override
    public SelectClazzDTO selectClazzById(Integer id) {
        return clazzMapper.selectClazzById(id);
    }

    @Log
    @Override
    public int updateClazz(UpdateClazzParam param) {
        param.setUpdateTime(LocalDateTime.now());
        int i = clazzMapper.updateClazz(param);
        return i;
    }

    @Override
    public List<SelectClazzDTO> selectAll() {
        List<SelectClazzDTO> dtos = clazzMapper.selectAll();
        return dtos;
    }


}
